home *** CD-ROM | disk | FTP | other *** search
/ Clickx 47 / Clickx 47.iso / assets / software / Miro_Installer.exe / xulrunner / chrome / toolkit.jar / content / mozapps / plugins / pluginInstallerDatasource.js next >
Encoding:
Text File  |  2005-07-14  |  7.1 KB  |  173 lines

  1. /* ***** BEGIN LICENSE BLOCK *****
  2.  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  3.  *
  4.  * The contents of this file are subject to the Mozilla Public License Version
  5.  * 1.1 (the "License"); you may not use this file except in compliance with
  6.  * the License. You may obtain a copy of the License at
  7.  * http://www.mozilla.org/MPL/
  8.  *
  9.  * Software distributed under the License is distributed on an "AS IS" basis,
  10.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11.  * for the specific language governing rights and limitations under the
  12.  * License.
  13.  *
  14.  * The Original Code is Plugin Finder Service.
  15.  *
  16.  * The Initial Developer of the Original Code is
  17.  * IBM Corporation.
  18.  * Portions created by the IBM Corporation are Copyright (C) 2004-2005
  19.  * IBM Corporation. All Rights Reserved.
  20.  *
  21.  * Contributor(s):
  22.  *   Doron Rosenberg <doronr@us.ibm.com>
  23.  *
  24.  * Alternatively, the contents of this file may be used under the terms of
  25.  * either the GNU General Public License Version 2 or later (the "GPL"), or
  26.  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  27.  * in which case the provisions of the GPL or the LGPL are applicable instead
  28.  * of those above. If you wish to allow use of your version of this file only
  29.  * under the terms of either the GPL or the LGPL, and not to allow others to
  30.  * use your version of this file under the terms of the MPL, indicate your
  31.  * decision by deleting the provisions above and replace them with the notice
  32.  * and other provisions required by the GPL or the LGPL. If you do not delete
  33.  * the provisions above, a recipient may use your version of this file under
  34.  * the terms of any one of the MPL, the GPL or the LGPL.
  35.  *
  36.  * ***** END LICENSE BLOCK ***** */
  37.  
  38. const RDF_NS = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
  39. const PFS_NS = "http://www.mozilla.org/2004/pfs-rdf#";
  40.  
  41. function nsRDFItemUpdater(aClientOS, aChromeLocale){
  42.   this._rdfService = Components.classes["@mozilla.org/rdf/rdf-service;1"]
  43.                         .getService(Components.interfaces.nsIRDFService);
  44.   this._os = Components.classes["@mozilla.org/observer-service;1"]
  45.                        .getService(Components.interfaces.nsIObserverService);
  46.  
  47.   var app = Components.classes["@mozilla.org/xre/app-info;1"]
  48.                       .getService(Components.interfaces.nsIXULAppInfo);
  49.   this.appID = app.ID;
  50.   this.buildID = app.platformBuildID;
  51.  
  52.   this.clientOS = aClientOS;
  53.   this.chromeLocale = aChromeLocale;
  54.  
  55.   var prefBranch = Components.classes["@mozilla.org/preferences-service;1"]
  56.                              .getService(Components.interfaces.nsIPrefBranch);
  57.   this.dsURI = prefBranch.getCharPref("pfs.datasource.url");
  58. }
  59.  
  60. nsRDFItemUpdater.prototype = {
  61.   checkForPlugin: function (aPluginRequestItem){
  62.     var dsURI = this.dsURI;
  63.     // escape the mimetype as mimetypes can contain '+', which will break pfs.
  64.     dsURI = dsURI.replace(/%PLUGIN_MIMETYPE%/g, encodeURIComponent(aPluginRequestItem.mimetype));
  65.     dsURI = dsURI.replace(/%APP_ID%/g, this.appID);
  66.     dsURI = dsURI.replace(/%APP_VERSION%/g, this.buildID);
  67.     dsURI = dsURI.replace(/%CLIENT_OS%/g, this.clientOS);
  68.     dsURI = dsURI.replace(/%CHROME_LOCALE%/g, this.chromeLocale);
  69.  
  70.     var ds = this._rdfService.GetDataSource(dsURI);
  71.     var rds = ds.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource)
  72.     if (rds.loaded)
  73.       this.onDatasourceLoaded(ds, aPluginRequestItem);
  74.     else {
  75.       var sink = ds.QueryInterface(Components.interfaces.nsIRDFXMLSink);
  76.       sink.addXMLSinkObserver(new nsPluginXMLRDFDSObserver(this, aPluginRequestItem));
  77.     }
  78.   },
  79.  
  80.   onDatasourceLoaded: function pfs_onDatasourceLoaded (aDatasource, aPluginRequestItem){
  81.     var container = Components.classes["@mozilla.org/rdf/container;1"].
  82.                   createInstance(Components.interfaces.nsIRDFContainer);
  83.     var resultRes = this._rdfService.GetResource("urn:mozilla:plugin-results:" + aPluginRequestItem.mimetype);
  84.     var pluginList = aDatasource.GetTarget(resultRes, this._rdfService.GetResource(PFS_NS+"plugins"), true);
  85.  
  86.     var pluginInfo = null;
  87.   
  88.     container = Components.classes["@mozilla.org/rdf/container;1"].createInstance(Components.interfaces.nsIRDFContainer);
  89.     try {
  90.       container.Init(aDatasource, pluginList);
  91.  
  92.       var children = container.GetElements();
  93.       var target;
  94.  
  95.       // get the first item
  96.       var child = children.getNext();
  97.       if (child instanceof Components.interfaces.nsIRDFResource){
  98.         var name = this._rdfService.GetResource("http://www.mozilla.org/2004/pfs-rdf#updates");
  99.         target = aDatasource.GetTarget(child, name, true);
  100.       }
  101.  
  102.       try {
  103.         container.Init(aDatasource, target);
  104.         target = null;
  105.         children = container.GetElements();
  106.  
  107.         var child = children.getNext();
  108.         if (child instanceof Components.interfaces.nsIRDFResource){
  109.           target = child;
  110.         }
  111.  
  112.         function getPFSValueFromRDF(aValue, aDatasource, aRDFService){
  113.           var rv = null;
  114.  
  115.           var myTarget = aDatasource.GetTarget(target, aRDFService.GetResource(PFS_NS + aValue), true);
  116.           if (myTarget)
  117.             rv = myTarget.QueryInterface(Components.interfaces.nsIRDFLiteral).Value;
  118.  
  119.           return rv;
  120.         }
  121.  
  122.         pluginInfo = new Object();
  123.         pluginInfo.name = getPFSValueFromRDF("name", aDatasource, this._rdfService);
  124.         pluginInfo.pid = getPFSValueFromRDF("guid", aDatasource, this._rdfService);
  125.         pluginInfo.version = getPFSValueFromRDF("version", aDatasource, this._rdfService);
  126.         pluginInfo.IconUrl = getPFSValueFromRDF("IconUrl", aDatasource, this._rdfService);
  127.         pluginInfo.XPILocation = getPFSValueFromRDF("XPILocation", aDatasource, this._rdfService);
  128.         pluginInfo.InstallerShowsUI = getPFSValueFromRDF("InstallerShowsUI", aDatasource, this._rdfService);
  129.         pluginInfo.manualInstallationURL = getPFSValueFromRDF("manualInstallationURL", aDatasource, this._rdfService);
  130.         pluginInfo.requestedMimetype = getPFSValueFromRDF("requestedMimetype", aDatasource, this._rdfService);
  131.         pluginInfo.licenseURL = getPFSValueFromRDF("licenseURL", aDatasource, this._rdfService);
  132.         pluginInfo.needsRestart = getPFSValueFromRDF("needsRestart", aDatasource, this._rdfService);
  133.       }
  134.       catch (ex){}
  135.     }
  136.     catch (ex){}
  137.     
  138.     gPluginInstaller.pluginInfoReceived(pluginInfo);
  139.   },
  140.  
  141.   onDatasourceError: function pfs_onDatasourceError (aPluginRequestItem, aError){
  142.     this._os.notifyObservers(aPluginRequestItem, "error", aError);
  143.     gPluginInstaller.pluginInfoReceived(null);
  144.   },
  145. };
  146.  
  147. function nsPluginXMLRDFDSObserver(aUpdater, aPluginRequestItem){
  148.   this._updater = aUpdater;
  149.   this._item    = aPluginRequestItem;
  150. }
  151.  
  152. nsPluginXMLRDFDSObserver.prototype = 
  153.   _updater  : null,
  154.   _item     : null,
  155.  
  156.   // nsIRDFXMLSinkObserver
  157.   onBeginLoad: function(aSink){},
  158.   onInterrupt: function(aSink){},
  159.   onResume: function(aSink){},
  160.   onEndLoad: function(aSink){
  161.     aSink.removeXMLSinkObserver(this);
  162.     
  163.     var ds = aSink.QueryInterface(Components.interfaces.nsIRDFDataSource);
  164.     this._updater.onDatasourceLoaded(ds, this._item);
  165.   },
  166.   
  167.   onError: function(aSink, aStatus, aErrorMsg){  
  168.     aSink.removeXMLSinkObserver(this);   
  169.     this._updater.onDatasourceError(this._item, aStatus.toString());
  170.   }
  171. };
  172.